// DArc1.cpp: implementation of the DArc class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "resourcemake.h"
#include "DArc.h"
#include "resourcemakeDlg.h"
#include <wingdi.h>
#include <complex>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

DArc::DArc()
{
	this->m_Type=SHARP_ARC;
	this->LineWidth = 1;
	this->m_bFill = 1;
	this->startX=30;
	this->startY=21;
	this->endX=30+52*(CDrawElement::dscrx*4/3);
	this->endY=21+52*(CDrawElement::dscry*4/3);
	int abbenginr=30;
	int abbengine=120;
	this->abbenginr=260;
	this->abbengine=90;
}

DArc::~DArc()
{
	
}

void DArc::Draw(CDC* pDC){
	this->getRadian();	
	CPen cMyPen;
	cMyPen.CreatePen(LineStyle,LineWidth,LineColor);
	pDC->SelectObject(&cMyPen);
	//pDC->Ellipse(this->startX,this->startY,this->endX,this->endY); 	
	pDC->Arc(this->startX,this->startY,this->endX,this->endY,this->adbeginx,this->adbeginy,this->adendx,this->adendy);
	
}

CString DArc::getStyle()
{
	CString str="";
	
	
	
	str.Format("1:(%d,%d,0,0):1:(%d,%d,%d,%d):",this->abbenginr,this->abbengine,this->adendx,this->adendy,this->adbeginx,this->adbeginy);
	
	return str;
}

void DArc::getRadian(){
	
	double tmptx=(this->startX+this->endX)/2;
	double tmpty=(this->startY+this->endY)/2;
	this->adbeginx=(this->startX+this->endX)/2;
	this->adbeginy=this->startY;
	this->adendx=this->startX;
    this->adendy=(this->startY+this->endY)/2;
    double tmptb=tan(this->abbenginr);
    double tmptbe=tan(this->abbengine);
	
	double tmpa=(-this->startX+this->endX)/2;
	double tmpb=(-this->startY+this->endY)/2;
	if (tmpb>tmpa){
		double tmpc=tmpa;
		tmpa=tmpb;
		tmpb=tmpc;
	}
	
	double tmpy=(tmpa*tmpb);
	tmpy=tmpy/sqrt((pow(tmpa,2))+(pow(tmpb,2)*pow(tmptb,2)));
	double tmpx=tmptb*tmpy;
	
    if ((abbenginr<=90)||(abbenginr>=270)){
		adbeginx=tmptx-abs(tmpx);
	} else{
		adbeginx=tmptx+abs(tmpx);
	}
	
	if ((abbenginr<=180)&&(abbenginr>=0)){
		adbeginy=tmpty-abs(tmpy);
	} else{
		adbeginy=tmpty+abs(tmpy);
	}
	
	
	double tmpey=(tmpa*tmpb)/sqrt((pow(tmpa,2))+(pow(tmpb,2)*pow(tmptbe,2)));
	double tmpex=tmptbe*tmpey;
	
    if ((abbengine<=90)||(abbengine>=270)){
		adendx=tmptx-abs(tmpex);
	} else{
		adendx=tmptx+abs(tmpex);
	}
	
	if ((abbengine<=180)&&(abbengine>=0)){
		adendy=tmpty-abs(tmpey);
	} else{
		adendy=tmpty+abs(tmpey);
	}
	
	
	/*	this->adbeginx=(this->startX+this->endX)/2;
	this->adbeginy=this->startY;
	this->adendx=this->startX;
    this->adendy=(this->startY+this->endY)/2;*/
}
